	<script type="text/javascript">
		$(document).ready(function(){
			$("#tglklaim").datepicker({
		      dateFormat: "dd/mm/yy",
		      changeMonth: true,
		      changeYear: true
		    });
		});
		$(document).ready(function(){
			$("#tglmasuk").datepicker({
		      dateFormat: "dd/mm/yy",
		      changeMonth: true,
		      changeYear: true
		    });
		});
		$(document).ready(function(){
			$("#tglkeluar").datepicker({
		      dateFormat: "dd/mm/yy",
		      changeMonth: true,
		      changeYear: true
		    });
		});

		function aksiLayanan(){
			$("#master_layanan_kat").select2('open');
		}

		function aksiDiagnosa(){
			$("#master_diagnosa").select2('open');
		}
		<?php 
			foreach ($kat_penunjang as $value) { ?>
				function aksiPenunjang<?= $value['id_kategori_penunjang']?>(){
					$("#master_penunjang<?= $value['id_kategori_penunjang']?>").select2('open');
				}
		<?php }
		?>
	</script>
	<script type="text/javascript">
		$(document).ready(function () {
            $('#tglkeluar').on('change',function(){
                var keluar = $("#tglkeluar").val();
                var masuk = $("#tglmasuk").val();
                var dateK=new Date(keluar.replace(/^(\d{2})\/(\d{2})\/(\d{4})$/,"$3/$2/$1"));
                var dateM=new Date(masuk.replace(/^(\d{2})\/(\d{2})\/(\d{4})$/,"$3/$2/$1"));
                var mil=1000*60*60*24;
                //var days  = (dateK - dateM)/mil;
                var days  = (Math.abs(dateK-dateM)/86400000);
                document.getElementById('lama_rawat').value = days+" Hari";
            });
        });
	</script>
		<div class="row">
		    <div class="col-xs-12">
		        <div class="box box-primary">
		            <div class="box-header">
		                <h3 class="box-title">Tambah Data Klaim</h3>
		            </div><!-- /.box-header -->
		            <?php echo form_open('klaim/save', array('role' => 'form', 'id' => 'form'));?>
		            <div class="box-body col-xs-12 col-lg-6">				        
	                    <!-- text input -->
	                    <div class="form-group">
	                        <label>Kode Klaim</label>
	                        <div class="input-group input-group-sm">
	                       		<input class="form-control" name="kd_klaim" id="kd_klaim" type="text" placeholder="Masukkan kode klaim" style="z-index:0;">
	                       		<span class="input-group-btn">
	                       			<a class="btn btn-info btn-flat" href="#" onClick="return kd_peserta()"><i class="fa fa-check"></i></a>
	                       		</span>
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label>No. Peserta</label>
	                       	<input class="form-control input-sm" name="nopeserta" id="nopeserta" type="text" disabled>
	                    </div>
	                    <div class="form-group">
	                        <label>Nama Peserta</label>
	                       	<input class="form-control input-sm" name="nama" id="nama" type="text" readonly="">
	                    </div>
	                     <div class="form-group">
	                        <label>TTL Peserta</label>
	                       	<input class="form-control input-sm" name="ttl" id="ttl" type="text" disabled>
	                    </div>
	                    <div class="form-group">
	                        <label>Alamat Peserta</label>
	                       	<input class="form-control input-sm" name="alamat" id="alamat" type="text" disabled>
	                    </div>
	                    <div class="form-group">
	                        <label>No. DMK</label>
	                       	<input class="form-control input-sm" name="dmk" id="dmk" type="text" placeholder="No. DMK">
	                    </div>
	                    <div class="form-group">
	                        <label>Dokter</label><br/>
	                       <select class="form-control input-sm dokter" name="dokter" id="dokter" style="width:100%;">
	                       </select>
	                    </div>
		            </div>
		            <div class="box-body col-xs-12 col-lg-6">				        
	                    
	                    <div class="form-group">
		                    <label>Tanggal Klaim</label>
		                    <input class="form-control input-sm" name="tglklaim" id="tglklaim" type="text" placeholder="Tanggal Klaim..."> 
		                 </div>
		                 <div class="form-group">
		                    <label>Tanggal Masuk</label>
		                    <input class="form-control input-sm" name="tglmasuk" id="tglmasuk" type="text" placeholder="Tanggal Masuk..."> 
		                 </div>
		                 <div class="form-group">
		                    <label>Tanggal Keluar</label>
		                    <input class="form-control input-sm tgl" name="tglkeluar" id="tglkeluar" type="text" placeholder="Tanggal Keluar..."> 
		                 </div>
		                 <div class="form-group">
		                    <label>Lama Rawat</label>
		                    <input class="form-control input-sm" name="lama_rawat" id="lama_rawat" type="text" disabled> 
		                 </div>
		                 <div class="form-group">
		                    <label>No. RM </label>
		                    <input class="form-control input-sm" name="norm" type="text" placeholder="No. RM"> 
		                 </div>
		                 <div class="form-group">
	                       <label>Unit</label><br/>
	                       <select class="form-control input-sm unit" name="unit" id="unit" style="width:100%;">
	                       </select>
	                    </div>
		            </div>
		            <div class="box-body col-xs-12">
	                    <div class="form-group">
		                    <label>Keterangan</label>
		                    <textarea name="keterangan" class="form-control input-sm"></textarea>
		                 </div>
		            </div>
		            <div class="box-body col-xs-12">
                         <button type="submit" id="btn" class="btn btn-sm btn-primary btn-flat" disabled=""><i class="fa fa-floppy-o"></i> Simpan</button>
                    </div>
					<?php echo form_close();?>
		            <div class="box-body" id="tab" style="display:none;">
		            	<!-- Nav tabs -->
						  <ul class="nav nav-tabs" role="tablist">
						    <li role="presentation" class="active"><a href="#layanan" onclick="aksiLayanan();" aria-controls="layanan" role="tab" data-toggle="tab">Layanan</a></li>
						    <li role="presentation"><a href="#diagnosa" onclick="aksiDiagnosa();" aria-controls="diagnosa" role="tab" data-toggle="tab">Diagnosa</a></li>
						  <?php 
						  foreach ($kat_penunjang as $value) { ?>
						  	<li role="presentation"><a href="#<?= convert_to_slug($value['kategori_penunjang'])?>" onclick="aksiPenunjang<?= $value['id_kategori_penunjang']?>();" aria-controls="<?= $value['kategori_penunjang']?>" role="tab" data-toggle="tab"><?= $value['kategori_penunjang']?></a></li>
						 <?php }
						  ?>
						    
						  </ul>

						  <!-- Tab panes -->
						  <div class="tab-content" style="width:100%">
						    <div role="tabpanel" class="tab-pane fade in active" id="layanan">
						    	<label>Layanan</label><br/><!--
						    	<label class="pull-right">Total </label><input type="text" name="ltotal" id="ltotal" disabled="">
								-->
								<span class="notif notif-danger" id="notif_layanan" style="display:none;">
				            		<i class="fa fa-check"></i>
				            		Maaf, layanan yang anda input sudah ada
				            		<button type="button" class="close">&times;</button>
				            	</span>
					            <table class="table table-borderless table-hover table-condensed table-striped">
					              <thead>
					              	<tr>
					              		<th width="2%">#</th>
					              		<th width="15%">Kategori Layanan</th>
					              		<th width="20%">Layanan</th>
					              		<th width="10%">Tarif Perda</th>
					              		<th width="5%">Jumlah</th>
					              		<th width="10%">Tarif Diminta</th>
					              		<th width="15%">Sub Total</th>
					              		<th width="10%">
					              		
					              		</th>
					              	</tr>
					              </thead>
					              <form id="formLayanan">
					              <thead>
					              	<tr>

					              		<th></th>
					              		<th width="15%" id="pilih_layanan_kat">
					              		</th>
					              		<th width="20%" id="pilih_layanan">
					              		</th>
					              		<th width="10%">
					              			<input type="hidden" name="kd_klaim2" id="kd_klaim2">
					              			<input class="form-control input-sm" name="ltarif_perda" id="ltarif_perda" type="text" disabled=""> 
					              		</th>
					              		<th width="5%">
					              			<input class="form-control input-sm" name="ljumlah" id="ljumlah" type="text" placeholder=""> 
					              		</th>
					              		<th width="10%">
					              			<input class="form-control input-sm" name="ltarif_diminta" id="ltarif_diminta" type="text" placeholder="Tarif Diminta"> 
					              		</th>
					              		<th width="15%">
					              			<input class="form-control input-sm lsubtotal" name="lsubtotal" id="lsubtotal" type="text" disabled=""> 
					              		</th>
					              		<th width="10%">
					              			<button id="savel" type="button" class="btn btn-sm btn-success btn-flat"><i class="fa fa-floppy-o"></i> Simpan</button>
					              		</th>
					              	</tr>
					              </thead>
					              </form>		
					              <tbody id="tbl-layanan">            
					                                  
					              </tbody>
					              
					            </table>
						    </div>
						    <div role="tabpanel" class="tab-pane fade" id="diagnosa" style="width:100%">
						    	<label>Diagnosa</label>
						    	<span class="notif notif-danger" id="notif_diagnosa" style="display:none;">
				            		<i class="fa fa-check"></i>
				            		Maaf, diagnosa yang anda input sudah ada
				            		<button type="button" class="close">&times;</button>
				            	</span>
					            <table class="table table-borderless table-hover table-condensed table-striped" style="width:100%;">
					              <thead>
					              	<tr>
					              		<th width="2%">#</th>
					              		<th width="30%">Diagnosa</th>
					              		<th width="10%"></th>
					              	</tr>
					              </thead>
					              <thead>
					              <form id="formDiagnosa">
					              	<tr>

					              		<th></th>
					              		<th>
					              			<input type="hidden" name="kd_klaim2" id="kd_klaim2">
					              			<select class="form-control input-sm" name="master_diagnosa" id="master_diagnosa" style="width:200px">
					              				
					              			<?php
					              				foreach ($diagnosa as $value) { ?>
					              					<option value="<?= $value['kd_diagnosa']?>"><?= $value['diagnosa']?></option>
					              			<?php	}
					              			?>
					              				
					              			</select>
					              		</th>
					              		<th width="10%">
					              			<button id="saved" type="button" class="btn btn-sm btn-success btn-flat"><i class="fa fa-floppy-o"></i> Simpan</button>
					              		</th>
					              	</tr>
					              </form>
					              </thead>		
					              <tbody id="tbl-diagnosa">            
					                                      
					              </tbody>
					              <!--
					              <tfoot>
					                <tr>
					                  <td colspan="6" align="right">
					                    <a onClick="return add_layanan()" onclick="" class="btn btn-primary btn-xs btn-flat">
					                      <i class="fa fa-fw fa-plus"></i>
					                    </a>
					                  </td>
					                </tr>            
					              </tfoot> -->
					            </table>
						    </div>
						    <?php 
							  foreach ($kat_penunjang as $value) { ?>
							 <div role="tabpanel" class="tab-pane fade" id="<?= convert_to_slug($value['kategori_penunjang']) ?>">
						    	<label><?= $value['kategori_penunjang'] ?></label>
						    	<span class="notif notif-danger" id="notif_penunjang<?= $value['id_kategori_penunjang'] ?>" style="display:none;">
				            		<i class="fa fa-check"></i>
				            		Maaf, penunjang yang anda input sudah ada
				            		<button type="button" class="close">&times;</button>
				            	</span>
						    	<table class="table table-borderless table-hover table-condensed table-striped">
					              <thead>
					              	<tr>
					              		<th width="2%">#</th>
					              		<th width="20%">Penunjang</th>
					              		<th width="10%">Tarif Perda</th>
					              		<th width="5%">Jumlah</th>
					              		<th width="10%">Tarif Diminta</th>
					              		<th width="15%">Sub Total</th>
					              		<th width="10%">
					              		
					              		</th>
					              	</tr>
					              </thead>
					              <form id="formPenunjang<?= $value['id_kategori_penunjang']?>">
					              <thead>
					              	<tr>

					              		<th></th>
					              		<th width="20%" id="pilih_penunjang<?= $value['id_kategori_penunjang']?>">
					              		</th>
					              		<th width="10%">
					              			<input type="hidden" name="kd_klaim2" id="kd_klaim2">
					              			<input class="form-control input-sm" name="ptarif_perda<?= $value['id_kategori_penunjang']?>" id="ptarif_perda<?= $value['id_kategori_penunjang']?>" type="text" disabled=""> 
					              		</th>
					              		<th width="5%">
					              			<input class="form-control input-sm" name="pjumlah<?= $value['id_kategori_penunjang']?>" id="pjumlah<?= $value['id_kategori_penunjang']?>" type="text" placeholder=""> 
					              		</th>
					              		<th width="10%">
					              			<input class="form-control input-sm" name="ptarif_diminta<?= $value['id_kategori_penunjang']?>" id="ptarif_diminta<?= $value['id_kategori_penunjang']?>" type="text" placeholder="Tarif Diminta"> 
					              		</th>
					              		<th width="15%">
					              			<input class="form-control input-sm psubtotal<?= $value['id_kategori_penunjang']?>" name="psubtotal<?= $value['id_kategori_penunjang']?>" id="psubtotal<?= $value['id_kategori_penunjang']?>" type="text" disabled=""> 
					              		</th>
					              		<th width="10%">
					              			<button id="savep<?= $value['id_kategori_penunjang']?>" type="button" class="btn btn-sm btn-success btn-flat"><i class="fa fa-floppy-o"></i> Simpan</button>
					              		</th>
					              	</tr>
					              </thead>
					              </form>		
					              <tbody id="tbl-penunjang<?= $value['id_kategori_penunjang']?>">            
					                                  
					              </tbody>
					              
					            </table>
						    </div>
							 <?php }
							  ?>
						    
						  </div>
		            </div>
		            <div class="clearfix"></div>		                   
                    
		        </div><!-- /.box -->                            
		    </div>
		</div>

		<script type="text/javascript">
		$("#master_diagnosa").select2({
			    placeholder: "Pilih Diagnosa"
		});
		</script>
		<script>
		$("#form").validate({
			rules: {
				kd_klaim: {
					required: true
				},
			}
		});
		</script>
		<script type="text/javascript">
		  function kd_peserta(){
		    var send_data = {
		        kd_peserta: $("#kd_klaim").val(),
		        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
		      };

		    $.ajax({
		      type: "POST",
		      url: "<?php echo base_url() ?>klaim/get_klaim",
		      data: send_data,
		      cache: false,
		      dataType: 'json',
		      success: function(msg){
		        $("#nama").val(msg.nama);
		        $("#nopeserta").val(msg.nopeserta);
		        $("#alamat").val(msg.alamat);
		        $("#ttl").val(msg.ttl);
		        $("#kd_ppk").val(msg.kd_ppk);
		        if (msg.stts=="ada") {
		        	document.getElementById("tab").style.display = "inline-block";
		        	document.getElementById("kd_klaim2").value = $("#kd_klaim").val();
		        	document.getElementById("btn").disabled = false;
		        }else{
		        	document.getElementById("tab").style.display = "none";
		        	document.getElementById("btn").disabled = true;
		        };
		        
		      }
		    });

		    //get unit
		    $.ajax({
		        url: '<?php echo base_url() ?>klaim/get_unit/'+$("#kd_klaim").val()+'',
			    //data: send_data,
			    cache: false,
			    dataType: 'html',
		        success: function(data){
		            $('#unit').html(data);
		            $("#unit").select2({
			            placeholder: "Pilih Unit"
			        });
		        }
		    });
		    //get dokter
		    $.ajax({
		        url: '<?php echo base_url() ?>klaim/get_dokter/'+$("#kd_klaim").val()+'',
			    //data: send_data,
			    cache: false,
			    dataType: 'html',
		        success: function(data){
		            $('#dokter').html(data);
		            $("#dokter").select2({
			            placeholder: "Pilih Dokter"
			        });
		        }
		    });
		    //get klaim layanan
		    $.ajax({
			      url: "<?php echo base_url() ?>klaim/get_layanan_klaim/"+$('#kd_klaim').val()+"",
			      cache: false,
			      dataType: 'html',
			      success: function(msg){
			        $("#tbl-layanan").html(msg);
			      }
			    });

			  //get klaim diagnosa
			$.ajax({
				url: "<?php echo base_url() ?>klaim/get_diagnosa_klaim/"+$('#kd_klaim').val()+"",
				cache: false,
				dataType: 'html',
				success: function(msg){
				$("#tbl-diagnosa").html(msg);
				}
			});

			
			<?php 
			foreach ($kat_penunjang as $value) { ?>
			//get klaim penunjang
			$.ajax({
				url: "<?php echo base_url() ?>klaim/get_penunjang_klaim/"+$('#kd_klaim').val()+"/<?= $value['id_kategori_penunjang']?>",
				cache: false,
				dataType: 'html',
				success: function(msg){
				$("#tbl-penunjang<?= $value['id_kategori_penunjang']?>").html(msg);
				}
			});
			//get penunjang 
			$.ajax({
		        url: '<?php echo base_url() ?>klaim/get_penunjang_pilihan/'+$("#kd_klaim").val()+'/<?= $value["id_kategori_penunjang"]?>',
			    //data: send_data,
			    cache: false,
			    dataType: 'html',
		        success: function(data){
		            $('#pilih_penunjang<?= $value["id_kategori_penunjang"]?>').html(data);
		            $("#master_penunjang<?= $value['id_kategori_penunjang'] ?>").select2({
			            placeholder: "Pilih Penunjang"
			        });
		        }
		    });

			<?php }
			?>
			// get layanan
		    /*$.ajax({
		        url: '<?php echo base_url() ?>klaim/get_layanan/'+$("#kd_klaim").val()+'',
			    //data: send_data,
			    cache: false,
			    dataType: 'html',
		        success: function(data){
		            $('#pilih_layanan').html(data);
		            $("#master_layanan").select2({
			            placeholder: "Pilih Layanan"
			        });
		        }
		    });*/

		    // get layanan kategori
		    $.ajax({
		        url: '<?php echo base_url() ?>klaim/get_layanan_kategori/'+$("#kd_klaim").val()+'',
			    //data: send_data,
			    cache: false,
			    dataType: 'html',
		        success: function(data){
		            $('#pilih_layanan_kat').html(data);
		            $("#master_layanan_kat").select2({
			            placeholder: "Pilih Kategori Layanan"
			        });
			        $("#master_layanan_kat").select2('open');
		        }
		    });
		  }

		  function pilih_layanan(kd_layanan)
			{
			    var data_send = {
			        layanan: kd_layanan,
			        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
			      };
			    $.ajax({
			      type: "POST",
			      url: "<?php echo base_url() ?>klaim/get_layanan_by",
			      data: data_send,
			      cache: false,
			      dataType: 'json',
			      success: function(msg){
			        $("#ltarif_perda").val(msg.tarif);
			        $("#lsubtotal").val(msg.tarif);
			        $("#ltarif_diminta").val(msg.tarif);
			        $("#kd_layanan").val(msg.kd_layanan);
			        $("#ljumlah").val(msg.jumlah);
			      }
			    }); 
			}

			function pilih_layanan_kat(kat_layanan)
			{
			    var data_send = {
			        kategori: kat_layanan,
			        klaim: $("#kd_klaim").val(),
			        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
			      };
			    $.ajax({
			      type: "POST",
			      url: "<?php echo base_url() ?>klaim/get_layanan",
			      data: data_send,
			      cache: false,
			      dataType: 'html',
			      success: function(data){
			        $('#pilih_layanan').html(data);
		            $("#master_layanan").select2({
			            placeholder: "Pilih Layanan"
			        });
			        $("#master_layanan").select2('open');
			      }
			    }); 
			}

			function get_layanan_klaim()
			{
			    $.ajax({
			      url: "<?php echo base_url() ?>klaim/get_layanan_klaim/"+$('#kd_klaim').val()+"",
			      cache: false,
			      dataType: 'html',
			      success: function(msg){
			        $("#tbl-layanan").html(msg);
			      }
			    }); 
			}

			

		</script>
		<script type="text/javascript">
		        $(document).ready(function () {
		            $('#ljumlah').keyup(function(){
		                var jml = parseInt(document.getElementById("ljumlah").value);
		                var tarif = parseInt(document.getElementById("ltarif_diminta").value);
		                var tot=jml*tarif;
		                document.getElementById('lsubtotal').value = tot;

		                
		            });
		            $('#ltarif_diminta').keyup(function(){
		                var jml = parseInt(document.getElementById("ljumlah").value);
		                var tarif = parseInt(document.getElementById("ltarif_diminta").value);
		                var tot=jml*tarif;
		                document.getElementById('lsubtotal').value = tot;
		            });
		        });

		</script>
		<script type="text/javascript">
		//save layanan
	    $(document).ajaxComplete(function(){
	    	$('#formLayanan').validate({
	            rules: {
	                ljumlah: {
	                    required: true
	                },
	                master_layanan: {
	                    required: true
	                },
	                ltarif_diminta: {
	                    required: true
	                },
	            },
	        });

	        $("#savel").click(function() {
	            //jika valid
	            if($("#master_layanan").val()!="" && $("#ljumlah").val()>0 && $("#ltarif_diminta").val()>0){
	            var form_data = {
	                kd_layanan: $("#master_layanan").val(),
	                kd_klaim: $("#kd_klaim2").val(),
	                tarif_perda: $("#ltarif_perda").val(),
	                jumlah: $("#ljumlah").val(),
	                tarif_diminta: $("#ltarif_diminta").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
	                type: "POST",
	                data: form_data,
	                url: "<?php echo site_url('klaim/simpan_layanan');?>",
	                error: function(e){
	                	document.getElementById("notif_layanan").style.display="block";
	                	document.getElementById("formLayanan").reset();
						$("#master_layanan").select2('open');
	                },
	                success: function(e) {
	                	document.getElementById("notif_layanan").style.display="none";
	                    $.ajax({
					      url: "<?php echo base_url() ?>klaim/get_layanan_klaim/"+$('#kd_klaim').val()+"",
					      cache: false,
					      dataType: 'html',
					      success: function(msg){
					        $("#tbl-layanan").html(msg);
							document.getElementById("formLayanan").reset();
							$("#master_layanan").select2('open');
					      }
					    });
	                },
	            });
	            stopPropagation();
	          }
	        });

			$("#ljumlah").keypress(function(e) {
				var keyCode = e.keyCode || e.which;
	            if(keyCode==13){
	            //jika valid
	            if($("#master_layanan").val()!="" && $("#ljumlah").val()>0 && $("#ltarif_diminta").val()>0){
	            var form_data = {
	                kd_layanan: $("#master_layanan").val(),
	                kd_klaim: $("#kd_klaim2").val(),
	                tarif_perda: $("#ltarif_perda").val(),
	                jumlah: $("#ljumlah").val(),
	                tarif_diminta: $("#ltarif_diminta").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
	                type: "POST",
	                data: form_data,
	                url: "<?php echo site_url('klaim/simpan_layanan');?>",
	                error: function(e){
	                	document.getElementById("notif_layanan").style.display="block";
	                	document.getElementById("formLayanan").reset();
						$("#master_layanan").select2('open');
	                },
	                success: function(e) {
	                	document.getElementById("notif_layanan").style.display="none";
	                    $.ajax({
					      url: "<?php echo base_url() ?>klaim/get_layanan_klaim/"+$('#kd_klaim').val()+"",
					      cache: false,
					      dataType: 'html',
					      success: function(msg){
					        $("#tbl-layanan").html(msg);
							document.getElementById("formLayanan").reset();
							$("#master_layanan").select2('open');
					      }
					    });
	                },
	            });
	            stopPropagation();
	          }
	          }
	        });

			$("#ltarif_diminta").keypress(function(e) {
				var keyCode = e.keyCode || e.which;
	            if(keyCode==13){
	            //jika valid
	            if($("#master_layanan").val()!="" && $("#ljumlah").val()>0 && $("#ltarif_diminta").val()>0){
	            var form_data = {
	                kd_layanan: $("#master_layanan").val(),
	                kd_klaim: $("#kd_klaim2").val(),
	                tarif_perda: $("#ltarif_perda").val(),
	                jumlah: $("#ljumlah").val(),
	                tarif_diminta: $("#ltarif_diminta").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
	                type: "POST",
	                data: form_data,
	                url: "<?php echo site_url('klaim/simpan_layanan');?>",
	                error: function(e){
	                	document.getElementById("notif_layanan").style.display="block";
	                	document.getElementById("formLayanan").reset();
						$("#master_layanan").select2('open');
	                },
	                success: function(e) {
	                	document.getElementById("notif_layanan").style.display="none";
	                    $.ajax({
					      url: "<?php echo base_url() ?>klaim/get_layanan_klaim/"+$('#kd_klaim').val()+"",
					      cache: false,
					      dataType: 'html',
					      success: function(msg){
					        $("#tbl-layanan").html(msg);
							document.getElementById("formLayanan").reset();
							$("#master_layanan").select2('open');
					      }
					    });
	                },
	            });
	            stopPropagation();
	          }
	          }
	        });

	    });
	       
	     //delete layanan
	     function hapusLayanan(obj){  
		    if (confirm('Apakah data akan dihapus ?')) {
		      var data_delete = {
			        layanan: obj,
			        klaim: $('#kd_klaim').val(),
			        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
			      };
			    $.ajax({
			      type: "POST",
			      url: "<?php echo base_url() ?>klaim/delete_layanan",
			      data: data_delete,
			      cache: false,
			      dataType: 'html',
			      success: function(msg){
			        $("#tbl-layanan").html(msg);
			      }
			    });
		    }
		  }

		  //edit layanan
	     function editLayanan(obj){ 
		      var data_edit = {
			        layanan: obj,
			        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
			      };
			    $.ajax({
			      type: "POST",
			      url: "<?php echo base_url() ?>klaim/edit_layanan",
			      data: data_edit,
			      cache: false,
			      dataType: 'html',
			      success: function(msg){
			        $("#div_"+obj).html(msg);
			        $('#eljumlah').keyup(function(){
		                var jml = parseInt(document.getElementById("eljumlah").value);
		                var tarif = parseInt(document.getElementById("eltarif_diminta").value);
		                var tot=jml*tarif;
		                document.getElementById('elsubtotal').value = tot;

		                //hitung total tarif
		                var arr = document.getElementsByClassName("elsubtotal");
		                var total=0;
		                for(var i=0;i<arr.length;i++){
		                    if(parseInt(arr[i].value))
		                        total += parseInt(arr[i].value);
		                }
		                document.getElementById('eltotal').value = total;
		            });
		            $('#eltarif_diminta').keyup(function(){
		                var jml = parseInt(document.getElementById("eljumlah").value);
		                var tarif = parseInt(document.getElementById("eltarif_diminta").value);
		                var tot=jml*tarif;
		                document.getElementById('elsubtotal').value = tot;
		            });
			      }
			    });
		  }
		  //update layanan
		  $(document).ajaxComplete(function(){
	    	$('#formLayanan').validate({
	            rules: {
	                ljumlah: {
	                    required: true
	                },
	                master_layanan: {
	                    required: true
	                },
	                ltarif_diminta: {
	                    required: true
	                },
	            },
	        });
	        $("#updatel").click(function() {
	            //jika valid
	            if($("#eljumlah").val()>0 && $("#eltarif_diminta").val()>0){
	            var lupdate_data = {
	                id: $("#id_layanan_klaim").val(),
	                tarif_perda: $("#eltarif_perda").val(),
	                jumlah: $("#eljumlah").val(),
	                tarif_diminta: $("#eltarif_diminta").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
	                type: "POST",
	                data: lupdate_data,
	                url: "<?php echo site_url('klaim/update_layanan');?>",
	                success: function(e) {
	                    $.ajax({
					      url: "<?php echo base_url() ?>klaim/get_layanan_klaim/"+$('#kd_klaim').val()+"",
					      cache: false,
					      dataType: 'html',
					      success: function(msg){
					        $("#tbl-layanan").html(msg);
					      }
					    });
	                },
	            });
	            stopPropagation();
	          }
	        });
	    });
		</script>
		<script type="text/javascript">
		//diagnosa
		//save diagnosa
		$("#saved").click(function() {
	            //jika valid
	        if($("#master_diagnosa").val()!=""){
	            var form_data = {
	                kd_diagnosa: $("#master_diagnosa").val(),
	                kd_klaim: $("#kd_klaim2").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
	                type: "POST",
	                data: form_data,
	                url: "<?php echo site_url('klaim/simpan_diagnosa');?>",
	                error: function(e){
	                	document.getElementById("notif_diagnosa").style.display="block";
	                	document.getElementById("formDiagnosa").reset();
						$("#master_diagnosa").select2('open');
	                },
	                success: function(e) {
	                    document.getElementById("notif_diagnosa").style.display="none";
	                	document.getElementById("formDiagnosa").reset();
						$("#master_diagnosa").select2('open');
	                    $.ajax({
					      url: "<?php echo base_url() ?>klaim/get_diagnosa_klaim/"+$('#kd_klaim').val()+"",
					      cache: false,
					      dataType: 'html',
					      success: function(msg){
					        $("#tbl-diagnosa").html(msg);
					      }
					    });
	                },
	            });
	            stopPropagation();
	          }
	        });
		//hapus diagnosa
		function hapusDiagnosa(obj){  
		    if (confirm('Apakah data akan dihapus ?')) {
		      var data_delete = {
			        diagnosa: obj,
			        klaim: $('#kd_klaim').val(),
			        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
			      };
			    $.ajax({
			      type: "POST",
			      url: "<?php echo base_url() ?>klaim/delete_diagnosa",
			      data: data_delete,
			      cache: false,
			      dataType: 'html',
			      success: function(msg){
			        $("#tbl-diagnosa").html(msg);
			      }
			    });
		    }
		  }
		</script>
		<!-- penunjang -->
		<script type="text/javascript">
		<?php 
		foreach ($kat_penunjang as $value) { ?>
		function get_penunjang_klaim<?= $value['id_kategori_penunjang']?>()
			{
			    $.ajax({
			      url: "<?php echo base_url() ?>klaim/get_penunjang_klaim/"+$('#kd_klaim').val()+"/<?= $value['id_kategori_penunjang']?>",
			      cache: false,
			      dataType: 'html',
			      success: function(msg){
			        $("#tbl-penunjang<?= $value['id_kategori_penunjang']?>").html(msg);
			      }
			    }); 
			}
		function pilih_penunjang<?= $value['id_kategori_penunjang']?>(kd_penunjang)
			{
			    var data_send = {
			        penunjang: kd_penunjang,
			        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
			      };
			    $.ajax({
			      type: "POST",
			      url: "<?php echo base_url() ?>klaim/get_penunjang_by",
			      data: data_send,
			      cache: false,
			      dataType: 'json',
			      success: function(msg){
			        $("#ptarif_perda<?= $value['id_kategori_penunjang']?>").val(msg.tarif);
			        $("#psubtotal<?= $value['id_kategori_penunjang']?>").val(msg.tarif);
			        $("#ptarif_diminta<?= $value['id_kategori_penunjang']?>").val(msg.tarif);
			        $("#kd_penunjang<?= $value['id_kategori_penunjang']?>").val(msg.kd_penunjang);
			        $("#pjumlah<?= $value['id_kategori_penunjang']?>").val(msg.jumlah);
			      }
			    }); 
			}
		//hitung sub total
		$(document).ready(function () {
		            $('#pjumlah<?= $value['id_kategori_penunjang']?>').keyup(function(){
		                var jml<?= $value['id_kategori_penunjang']?> = parseInt(document.getElementById("pjumlah<?= $value['id_kategori_penunjang']?>").value);
		                var tarif<?= $value['id_kategori_penunjang']?> = parseInt(document.getElementById("ptarif_diminta<?= $value['id_kategori_penunjang']?>").value);
		                var tot<?= $value['id_kategori_penunjang']?>=jml<?= $value['id_kategori_penunjang']?>*tarif<?= $value['id_kategori_penunjang']?>;
		                document.getElementById('psubtotal<?= $value['id_kategori_penunjang']?>').value = tot<?= $value['id_kategori_penunjang']?>;

		                
		            });
		            $('#ptarif_diminta<?= $value['id_kategori_penunjang']?>').keyup(function(){
		                var jml<?= $value['id_kategori_penunjang']?> = parseInt(document.getElementById("pjumlah<?= $value['id_kategori_penunjang']?>").value);
		                var tarif<?= $value['id_kategori_penunjang']?> = parseInt(document.getElementById("ptarif_diminta<?= $value['id_kategori_penunjang']?>").value);
		                var tot<?= $value['id_kategori_penunjang']?>=jml<?= $value['id_kategori_penunjang']?>*tarif<?= $value['id_kategori_penunjang']?>;
		                document.getElementById('psubtotal<?= $value['id_kategori_penunjang']?>').value = tot<?= $value['id_kategori_penunjang']?>;
		            });
		        });
		//save penunjang
		$("#savep<?= $value['id_kategori_penunjang']?>").click(function() {
	            //jika valid
	        if($("#master_penunjang<?= $value['id_kategori_penunjang']?>").val()!="" && $("#pjumlah<?= $value['id_kategori_penunjang']?>").val()>0 && $("#ptarif_diminta<?= $value['id_kategori_penunjang']?>").val()>0){
	            var form_data = {
	                kd_penunjang: $("#master_penunjang<?= $value['id_kategori_penunjang']?>").val(),
	                kd_klaim: $("#kd_klaim2").val(),
	                tarif_perda: $("#ptarif_perda<?= $value['id_kategori_penunjang']?>").val(),
	                jumlah: $("#pjumlah<?= $value['id_kategori_penunjang']?>").val(),
	                tarif_diminta: $("#ptarif_diminta<?= $value['id_kategori_penunjang']?>").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
	                type: "POST",
	                data: form_data,
	                url: "<?php echo site_url('klaim/simpan_penunjang');?>",
	                error: function(e){
	                	document.getElementById("notif_penunjang<?= $value['id_kategori_penunjang']?>").style.display="block";
	                	document.getElementById("formPenunjang<?= $value['id_kategori_penunjang']?>").reset();
						$("#master_penunjang<?= $value['id_kategori_penunjang']?>").select2('open');
	                },
	                success: function(e) {
	                	document.getElementById("notif_penunjang<?= $value['id_kategori_penunjang']?>").style.display="none";
	                    document.getElementById("formPenunjang<?= $value['id_kategori_penunjang']?>").reset();
						$("#master_penunjang<?= $value['id_kategori_penunjang']?>").select2('open');
	                    $.ajax({
							url: "<?php echo base_url() ?>klaim/get_penunjang_klaim/"+$('#kd_klaim').val()+"/<?= $value['id_kategori_penunjang']?>",
							cache: false,
							dataType: 'html',
							success: function(msg){
							$("#tbl-penunjang<?= $value['id_kategori_penunjang']?>").html(msg);
							}
						});
	                },
	            });
	            stopPropagation();
	          }
	        });

		$("#pjumlah<?= $value['id_kategori_penunjang']?>").keypress(function(e) {
	        var keyCode = e.keyCode || e.which;
	        if(keyCode==13){
	        //jika valid
	        if($("#master_penunjang<?= $value['id_kategori_penunjang']?>").val()!="" && $("#pjumlah<?= $value['id_kategori_penunjang']?>").val()>0 && $("#ptarif_diminta<?= $value['id_kategori_penunjang']?>").val()>0){
	            var form_data = {
	                kd_penunjang: $("#master_penunjang<?= $value['id_kategori_penunjang']?>").val(),
	                kd_klaim: $("#kd_klaim2").val(),
	                tarif_perda: $("#ptarif_perda<?= $value['id_kategori_penunjang']?>").val(),
	                jumlah: $("#pjumlah<?= $value['id_kategori_penunjang']?>").val(),
	                tarif_diminta: $("#ptarif_diminta<?= $value['id_kategori_penunjang']?>").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
	                type: "POST",
	                data: form_data,
	                url: "<?php echo site_url('klaim/simpan_penunjang');?>",
	                error: function(e){
	                	document.getElementById("notif_penunjang<?= $value['id_kategori_penunjang']?>").style.display="block";
	                	document.getElementById("formPenunjang<?= $value['id_kategori_penunjang']?>").reset();
						$("#master_penunjang<?= $value['id_kategori_penunjang']?>").select2('open');
	                },
	                success: function(e) {
	                	document.getElementById("notif_penunjang<?= $value['id_kategori_penunjang']?>").style.display="none";
	                    document.getElementById("formPenunjang<?= $value['id_kategori_penunjang']?>").reset();
						$("#master_penunjang<?= $value['id_kategori_penunjang']?>").select2('open');
	                    $.ajax({
							url: "<?php echo base_url() ?>klaim/get_penunjang_klaim/"+$('#kd_klaim').val()+"/<?= $value['id_kategori_penunjang']?>",
							cache: false,
							dataType: 'html',
							success: function(msg){
							$("#tbl-penunjang<?= $value['id_kategori_penunjang']?>").html(msg);
							}
						});
	                },
	            });
	            stopPropagation();
	          }
	          }
	        });

		$("#ptarif_diminta<?= $value['id_kategori_penunjang']?>").keypress(function(e) {
	        var keyCode = e.keyCode || e.which;
	        if(keyCode==13){
	        //jika valid
	        if($("#master_penunjang<?= $value['id_kategori_penunjang']?>").val()!="" && $("#pjumlah<?= $value['id_kategori_penunjang']?>").val()>0 && $("#ptarif_diminta<?= $value['id_kategori_penunjang']?>").val()>0){
	            var form_data = {
	                kd_penunjang: $("#master_penunjang<?= $value['id_kategori_penunjang']?>").val(),
	                kd_klaim: $("#kd_klaim2").val(),
	                tarif_perda: $("#ptarif_perda<?= $value['id_kategori_penunjang']?>").val(),
	                jumlah: $("#pjumlah<?= $value['id_kategori_penunjang']?>").val(),
	                tarif_diminta: $("#ptarif_diminta<?= $value['id_kategori_penunjang']?>").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
	                type: "POST",
	                data: form_data,
	                url: "<?php echo site_url('klaim/simpan_penunjang');?>",
	                error: function(e){
	                	document.getElementById("notif_penunjang<?= $value['id_kategori_penunjang']?>").style.display="block";
	                	document.getElementById("formPenunjang<?= $value['id_kategori_penunjang']?>").reset();
						$("#master_penunjang<?= $value['id_kategori_penunjang']?>").select2('open');
	                },
	                success: function(e) {
	                	document.getElementById("notif_penunjang<?= $value['id_kategori_penunjang']?>").style.display="none";
	                    document.getElementById("formPenunjang<?= $value['id_kategori_penunjang']?>").reset();
						$("#master_penunjang<?= $value['id_kategori_penunjang']?>").select2('open');
	                    $.ajax({
							url: "<?php echo base_url() ?>klaim/get_penunjang_klaim/"+$('#kd_klaim').val()+"/<?= $value['id_kategori_penunjang']?>",
							cache: false,
							dataType: 'html',
							success: function(msg){
							$("#tbl-penunjang<?= $value['id_kategori_penunjang']?>").html(msg);
							}
						});
	                },
	            });
	            stopPropagation();
	          }
	          }
	        });
		//hapus penunjang
		function hapusPenunjang<?= $value['id_kategori_penunjang']?>(obj){  
		    if (confirm('Apakah data akan dihapus ?')) {
		      var data_delete = {
			        penunjang: obj,
			        klaim: $('#kd_klaim').val(),
			        kategori: <?= $value['id_kategori_penunjang']?>,
			        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
			      };
			    $.ajax({
			      type: "POST",
			      url: "<?php echo base_url() ?>klaim/delete_penunjang",
			      data: data_delete,
			      cache: false,
			      success: function(msg){
			        $("#tbl-penunjang<?= $value['id_kategori_penunjang']?>").html(msg);
			      }
			    });
		    }
		  }

		  //edit penunjang
	     function editPenunjang<?= $value['id_kategori_penunjang']?>(obj){ 
		      var data_edit = {
			        penunjang: obj,
			        <?php echo $this->security->get_csrf_token_name(); ?>: "<?php echo $this->security->get_csrf_hash(); ?>",
			      };
			    $.ajax({
			      type: "POST",
			      url: "<?php echo base_url() ?>klaim/edit_penunjang",
			      data: data_edit,
			      cache: false,
			      dataType: 'html',
			      success: function(msg){
			        $("#divp_"+obj).html(msg);
			        $('#epjumlah').keyup(function(){
		                var jml= parseInt(document.getElementById("epjumlah").value);
		                var tarif= parseInt(document.getElementById("eptarif_diminta").value);
		                var tot=jml*tarif;
		                document.getElementById('epsubtotal').value = tot;
		                
		            });
		            $('#eptarif_diminta').keyup(function(){
		                var jml = parseInt(document.getElementById("epjumlah").value);
		                var tarif = parseInt(document.getElementById("eptarif_diminta").value);
		                var tot=jml*tarif;
		                document.getElementById('epsubtotal').value = tot;
		            });
			      }
			    });
		  }
		  //update penunjang
		  $(document).ajaxComplete(function(){
	    	$('#formEditPenunjang<?= $value['id_kategori_penunjang']?>').validate({
	            rules: {
	                pjumlah: {
	                    required: true
	                },
	                master_penunjang: {
	                    required: true
	                },
	                ptarif_diminta: {
	                    required: true
	                },
	            },
	        });
		  $("#updatep<?= $value['id_kategori_penunjang']?>").click(function() {
	            //jika valid
	            if($("#epjumlah<?= $value['id_kategori_penunjang']?>").val()>0 && $("#eptarif_diminta<?= $value['id_kategori_penunjang']?>").val()>0){
	            var pupdate_data = {
	                id: $("#id_penunjang_klaim<?= $value['id_kategori_penunjang']?>").val(),
	                tarif_perda: $("#eptarif_perda<?= $value['id_kategori_penunjang']?>").val(),
	                jumlah: $("#epjumlah<?= $value['id_kategori_penunjang']?>").val(),
	                tarif_diminta: $("#eptarif_diminta<?= $value['id_kategori_penunjang']?>").val(),
	                // ini harus ada, untuk scurity CI   
	                <?php echo $this->security->get_csrf_token_name();?>: '<?php echo $this->security->get_csrf_hash();?>'
	              };

	            $.ajax({
	                type: "POST",
	                data: pupdate_data,
	                url: "<?php echo site_url('klaim/update_penunjang');?>",
	                success: function(e) {
	                    $.ajax({
					      url: "<?php echo base_url() ?>klaim/get_penunjang_klaim/"+$('#kd_klaim').val()+"/<?= $value['id_kategori_penunjang']?>",
					      cache: false,
					      dataType: 'html',
					      success: function(msg){
					        $("#tbl-penunjang<?= $value['id_kategori_penunjang']?>").html(msg);
					      }
					    });
	                },
	            });
	            stopPropagation();
	          }
	        });
			});
	       
		<?php } ?>
		 
		</script>
		